﻿ 
<%@page import="com.hh.bss.util.StringHelper" %>
<%
  String companyId=request.getParameter("companyId");  
  
  if (StringHelper.isEmpty(companyId)) companyId="0";
  
%> 
	
<!DOCTYPE html>  

<html>  
<head>  
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
    <meta name="keywords" content="公司">  
    <meta name="description" content="公司">  
    <title>公司组织架构</title>  
    
    <%@ include file="/WEB-INF/inc/default.jsp"%>
    <jsp:include page="/WEB-INF/inc/dic.jsp"/>

</head>  
<body>  
    
      
    <ul id="tt" class="easyui-tree" data-options="url:'/customer/company/companyorg.do?companyId=<%=companyId%>',animate:true
    	,onContextMenu: function(e,node){
                e.preventDefault();
                $(this).tree('select',node.target);
                //alert(node.id);
                //console.log(node);
                //console.log(node.attributes.companyNodeType);
                
                if (node.id == 'rootNode') {
                     $('#mm_root').menu('show',{
                       left: e.pageX,
                       top: e.pageY
                     });
                  
                }else if (node.attributes.companyNodeType == 'DEPT') {
                     
                     $('#mm_dept').menu('show',{
                       left: e.pageX,
                       top: e.pageY
                     });
                     
                     
                  
                }else if (node.attributes.companyNodeType == 'TITLE') {
                     $('#mm_title').menu('show',{
                       left: e.pageX,
                       top: e.pageY
                     });
                }else if (node.attributes.companyNodeType == 'CV') {
                     $('#mm_cv').menu('show',{
                       left: e.pageX,
                       top: e.pageY
                     });
                }
                
                
            }
    	"></ul>  
     
    <div id="mm_root" class="easyui-menu" style="width:120px;">
        <div onclick="addDept()" data-options="iconCls:'icon-add'">新增部门</div>                      
        <div onclick="expand()">展开</div>
        <div onclick="collapse()">收起</div>
    </div> 
    <div id="mm_dept" class="easyui-menu" style="width:120px;">
        <div onclick="addDept()" data-options="iconCls:'icon-add'">新增部门</div>
        <div onclick="editDept()" data-options="iconCls:'icon-edit'">修改部门</div>
        <div onclick="deleteDept()" data-options="iconCls:'icon-remove'">删除部门</div>        
        <div onclick="addTitle()" data-options="iconCls:'icon-remove'">新增岗位</div>
        <div onclick="expand()">展开</div>
        <div onclick="collapse()">收起</div>
    </div>
    <div id="mm_title" class="easyui-menu" style="width:120px;">
        <div onclick="addTitle()" data-options="iconCls:'icon-add'">新增岗位</div>
        <div onclick="editTitle()" data-options="iconCls:'icon-edit'">修改岗位</div>
        <div onclick="deleteTitle()" data-options="iconCls:'icon-remove'">删除岗位</div>        
        <div onclick="addCv()" data-options="iconCls:'icon-add'">加入人选</div>
        <div onclick="expand()">展开</div>
        <div onclick="collapse()">收起</div>
    </div> 
    <div id="mm_cv" class="easyui-menu" style="width:120px;">       
        <div onclick="deleteCv()" data-options="iconCls:'icon-remove'">删除人员</div>        
        <div onclick="expand()">展开</div>
        <div onclick="collapse()">收起</div>
    </div> 
    
     <div id="dlg-dept" class="easyui-dialog" style="width:400px;height:200px;padding:10px 20px"  
            closed="true" >  
        <!--      
        <form id="fm-dept" method="post" novalidate>  
        	  	  	 <input type="hidden" name="id" > 
        	  	  	 <input type="hidden" name="companyId" >        	  	  	 
        	  	  	 <input type="hidden" name="parentId" >
	        		     <div class="fitem">  
                     <label style="width:100px">名称<font color="red">*</font>:</label>                                            
                     <input name="name" class="easyui-box easyui-validatebox"  required="true">                       
                   </div> 
	        		     <div class="fitem">  
                     <label style="width:100px">备注: </label>                     
                     <textarea name="comment" style="height:60px;width:150px"></textarea>
                   </div> 	        		             		     	        		     
        </form>  
        <div style="text-align:center">  
           <a href="javascript:void(0)" id="btn-save" class="easyui-linkbutton" iconCls="icon-ok" onclick="save('fm-dept','dlg-dept')">Save</a>  
           <a href="javascript:void(0)" id="btn-close" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg-dept').dialog('close')">关闭</a>  
        </div>  
        -->      
    </div> 
    
    <div id="dlg-title" style="display:none;">  
        <!--    
        <form id="fm-title" method="post" novalidate>  
        	  	  	 <input type="hidden" name="id" > 
        	  	  	 <input type="hidden" name="companyId" >
        	  	  	 <input type="hidden" name="deptId" >
        	  	  	 <input type="hidden" name="parentId" >
	        		     <div class="fitem">  
                     <label style="width:100px">名称<font color="red">*</font>:</label>                                            
                     <input name="name" class="easyui-box easyui-validatebox"  required="true">                       
                   </div> 
	        		     <div class="fitem">  
                     <label style="width:100px">备注: </label>                     
                     <textarea name="comment" style="height:60px;width:150px"></textarea>
                   </div> 	        		             		     	        		     
        </form>  
        <div style="text-align:center">  
           <a href="javascript:void(0)" id="btn-save" class="easyui-linkbutton" iconCls="icon-ok" onclick="save('fm-title','dlg-title')">Save</a>  
           <a href="javascript:void(0)" id="btn-close" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg-title').dialog('close')">关闭</a>  
        </div>        
        -->
    </div>
    
    
    <div id="wSelectCv" class="easyui-window" title="Modal Window" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:1100px;height:450px;padding:2px;">
        <iframe  frameborder="no"  src="" style="width:100%;height:95%"></iframe>
                
    </div>
    
    <script type="text/javascript">
    	var selectAddWin;
    	var optDeptWin = $.window({
		       		 title:"新增部门",
		       		 tplRef:"dlg-dept",//这个属性指定模板id
		       		 height:200,		       		 
		       		 closed:true,		       		 
		       		 onComplete:function(){
		       		 	  //窗口里面的初始化,最好是在这个事件里面进行
		       		 	  var curWin=this;
		       		 	  var doForm=curWin.find('#fm-dept');
		       		 	  curWin.doForm=doForm;
		       		 	  this.find("#btn-close").click(function(){		       		 	  	
		       		 	  	   curWin.window('close');
		       		 	  });
		       		 	  this.find("#btn-save").click(function(){	
		       		 	  	        	
		                 		  if (!doForm.form('validate')) return;
		                 		  
		                 		  doForm.form('submit',{  
                            url: curWin.url,  
                            onSubmit: function(){                              	  
                                return doForm.form('validate');  
                            },  
                            success: function(result){  
                                var result = eval('('+result+')');                      
                                if (result.success == true){  
                                    //$.messager.alert('信息',result.msg,'info');  
                                    alert(result.msg);
                                    curWin.window('close');
                                    curWin.openWin.reload();
                                    
                                } else {  
                                    //$.messager.alert('错误',result.msg,'error');
                                    alert(result.msg);
                                }  
                            }  
                       }); 		 
		              });
		       		   
		       		 }
		    });
    	 
    	 var optTitleWin = $.window({
		       		 title:"新增岗位",
		       		 tplRef:"dlg-title",//这个属性指定模板id
		       		 height:200,		       		 
		       		 closed:true,		       		 
		       		 onComplete:function(){
		       		 	  //窗口里面的初始化,最好是在这个事件里面进行
		       		 	  var curWin=this;
		       		 	  var doForm=curWin.find('#fm-title');
		       		 	  curWin.doForm=doForm;
		       		 	  this.find("#btn-close").click(function(){		       		 	  	
		       		 	  	   curWin.window('close');
		       		 	  });
		       		 	  this.find("#btn-save").click(function(){		       		 	  	
		                 		  if (!doForm.form('validate')) return;
		                 		  
		                 		  doForm.form('submit',{  
                            url: curWin.url,  
                            onSubmit: function(){                              	  
                                return doForm.form('validate');  
                            },  
                            success: function(result){  
                                var result = eval('('+result+')');                      
                                if (result.success == true){  
                                    //$.messager.alert('信息',result.msg,'info');  
                                    alert(result.msg);
                                    curWin.window('close');
                                    curWin.openWin.reload();
                                    
                                } else {  
                                    //$.messager.alert('错误',result.msg,'error');
                                    alert(result.msg);
                                }  
                            }  
                       }); 		 
		              });
		       		   
		       		 }
		    });
    	 
    	 function addDept(){
    	 	  var node = $('#tt').tree('getSelected');
    	 	  /*
    	 	  url='/customer/companyDept/save.do';
    	 	  $('#dlg-dept').dialog('open').dialog('setTitle','新增部门');    	 	 
    	 	  if (node.id == 'rootNode') { 
    	 	    $('#fm-dept input[name="companyId"]').attr("value",node.attributes.companyId);
    	 	    $('#fm-dept input[name="parentId"]').attr("value",'0');
    	 	  }else {
    	 	  	$('#fm-dept input[name="companyId"]').attr("value",node.attributes.companyId);
    	 	    $('#fm-dept input[name="parentId"]').attr("value",node.attributes.deptId);
    	 	  }*/
    	 	  optDeptWin.window('open'); 
          optDeptWin.openWin=window;    
          optDeptWin.url='/customer/companyDept/save.do';
          optDeptWin.doForm.form('clear');
          optDeptWin.window('setTitle','新增部门');
          
          optDeptWin.doForm.find('input[name="companyId"]').attr("value",node.attributes.companyId);
          if (node.id == 'rootNode') {     	 	    
    	 	    optDeptWin.doForm.find('input[name="parentId"]').attr("value",'0');
    	 	  }else {    	 	  	
    	 	    optDeptWin.doForm.find('input[name="parentId"]').attr("value",node.attributes.deptId);
    	 	  }
    	 	  
    	 	  
    	 }
    	 function editDept(){
    	 	  var node = $('#tt').tree('getSelected');
    	 	  //url='/customer/companyDept/update.do';
    	 	  //$('#dlg-dept').dialog('open').dialog('setTitle','修改部门');
    	 	  //$('#fm-dept').form('load','/customer/companyDept/get.do?id='+node.attributes.deptId); 
    	 	  optDeptWin.window('open'); 
          optDeptWin.openWin=window;    
          optDeptWin.url='/customer/companyDept/update.do';
          optDeptWin.doForm.form('clear');
          optDeptWin.window('setTitle','修改部门');
          optDeptWin.doForm.form('load','/customer/companyDept/get.do?id='+node.attributes.deptId);
    	 }
    	 function deleteDept(){    	              
    	 	        var node = $('#tt').tree('getSelected');
                   $.messager.confirm('重要提示','确定要删除?',function(r){  
                       if (r){  
                           $.post('/customer/companyDept/delete.do',{ids:node.attributes.deptId},function(result){  
                               if (result.success){                                     
                               } else {                                      
                                   $.messager.alert('错误',result.errorMsg,'error'); 
                               }  
                           },'json');  
                       }  
                   });  
               
    	 }
    	 function addTitle(){
    	 	  var node = $('#tt').tree('getSelected');
    	 	  /*
    	 	  url='/customer/companyDeptTitle/save.do';
    	 	  $('#dlg-title').dialog('open').dialog('setTitle','新增岗位');    	 	  
    	 	  $('#fm-title input[name="companyId"]').attr("value",node.attributes.companyId);
    	 	  $('#fm-title input[name="deptId"]').attr("value",node.attributes.deptId);
    	 	  if (node.attributes.titleId) $('#fm-title input[name="parentId"]').attr("value",node.attributes.titleId);
    	 	  else $('#fm-title input[name="parentId"]').attr("value",'0');
    	 	  */
    	 	  optTitleWin.window('open'); 
          optTitleWin.openWin=window;    
          optTitleWin.url='/customer/companyDeptTitle/save.do';
          optTitleWin.doForm.form('clear');
          optTitleWin.window('setTitle','新增岗位');
          
          optTitleWin.doForm.find('input[name="companyId"]').attr("value",node.attributes.companyId);
          optTitleWin.doForm.find('input[name="deptId"]').attr("value",node.attributes.deptId);
          if (node.attributes.titleId) optTitleWin.doForm.find('input[name="parentId"]').attr("value",node.attributes.titleId);
    	 	  else optTitleWin.doForm.find('input[name="parentId"]').attr("value",'0');
    	 	  
    	 }
    	 function editTitle(){
    	 	  var node = $('#tt').tree('getSelected');
    	 	  /*
    	 	  url='/customer/companyDeptTitle/update.do';
    	 	  $('#dlg-title').dialog('open').dialog('setTitle','修改岗位');
    	 	  $('#fm-title').form('load','/customer/companyDeptTitle/get.do?id='+node.attributes.titleId); 
    	 	  */
    	 	  optTitleWin.window('open'); 
          optTitleWin.openWin=window;    
          optTitleWin.url='/customer/companyDeptTitle/update.do';
          optTitleWin.doForm.form('clear');
          optTitleWin.window('setTitle','修改岗位');
          optTitleWin.doForm.form('load','/customer/companyDeptTitle/get.do?id='+node.attributes.titleId);
    	 }
    	 function deleteTitle(){
    	 	        var node = $('#tt').tree('getSelected');
                   $.messager.confirm('重要提示','确定要删除?',function(r){  
                       if (r){  
                           $.post('/customer/companyDeptTitle/delete.do',{ids:node.attributes.titleId},function(result){  
                               if (result.success){                                     
                               } else {                                      
                                   $.messager.alert('错误',result.errorMsg,'error'); 
                               }  
                           },'json');  
                       }  
                   });  
    	 }
    	  function addCv(){
    	 	  var node = $('#tt').tree('getSelected');    	 	  
    	 	  //$('#wSelectCv').window('open');
   	      //$('#wSelectCv').find('iframe')[0].contentWindow.location.href="/talent/cv/selectCvPage.do";    	 	  
   	      if (selectAddWin)
                 selectAddWin.window('open');
             else selectAddWin = $.window({
		      	   	title:"选择人选",
		      	   	url:"/talent/cv/selectCvPage.do",
		      	   	isIframe:true,
		      	   	height:380,
		      	   	modal:false,		      	   	
		      	   	width:1000,
		      	   	onComplete:function(jq,iframe){	
		      	   		         	   		   	      	   		
		      	   		   var fwindow = $.window.util.getFrameWindow(iframe);		      	   		
		      	   		   var ijq = fwindow.jQuery;		
		      	   		   var curWin=this;   
		      	   		   
		      	   		   var curWin=this;
					
					           fwindow.closeWin=function(){
					           	   curWin.window('close');					           	  
				             };
				             
				             fwindow.callback=curWin.openerWin.chooseCv;
				             
		      	   	}
		      	});
		      	selectAddWin.openerWin=window;  
    	 }
    	 function chooseCv(cv){
            //$('#fm input[name="company"]').attr("value",cv.name);
            //$('#fm input[name="companyId"]').attr("value",cv.id);
            var node = $('#tt').tree('getSelected');    	 	  
            $.post('/customer/companyCv/cvjoincompany.do',{cvIds:cv.id,companyId:node.attributes.companyId,deptId:node.attributes.deptId,titleId:node.attributes.titleId},function(result){  
                               if (result.success){                                     
                               } else {                                      
                                   $.messager.alert('错误',result.errorMsg,'error'); 
                               }  
                           },'json'); 
       }
    	 
    	 function deleteCv(){
            var node = $('#tt').tree('getSelected');    	 	  
            $.post('/customer/companyCv/extdelete.do',{ids:node.attributes.cvId},function(result){  
                               if (result.success){                                     
                               } else {                                      
                                   $.messager.alert('错误',result.errorMsg,'error'); 
                               }  
                           },'json');     	 	
    	 }
    	 function reload(){
    	 	  $('#tt').tree('reload');
    	 }
        function save(formid,dlgid){          	   
        	  if (!$('#'+formid).form('validate')) return; 
            $('#'+formid).form('submit',{  
                url: url,  
                onSubmit: function(){  
                    return $(this).form('validate');  
                },  
                success: function(result){  
                    var result = eval('('+result+')');  
                    console.log(result);
                    if (result.success == true){  
                        $.messager.alert('信息',result.msg,'info');  
                        if (dlgid) $('#'+dlgid).dialog('close');      // close the dialog  
                        //if (dgid) $('#'+dgid).datagrid('reload');    // reload the user data  
                        $('#tt').tree('reload');
                    } else {  
                        $.messager.alert('错误',result.msg,'error');
                    }  
                }  
            });  
        }    	 
        
    </script>	
</body>  
</html>